


module.exports = function(handler){

    let {Model, impl} = handler

    impl(Model, '$wrapper', function(){
        return this.$extra().getWrapper()
    })

    impl(Model, '$model', function(){
        return this.$wrapper().getModelName()
    })

    impl(Model, '$mount', function(){
        return this.$extra().getMount()
    })

    impl(Model, '$name', function(){
        return this.$extra().getName()
    })

    impl(Model, '$point', function(){
        return this.$extra().getPoint()
    })

    impl(Model, '$root', function(){
        return this.$extra().isRoot()
    })

    impl(Model, '$index', function(){
        let mount = this.$mount()
        if(null === mount){
            return -2 // 通过容器暴露标志ROOT=-2
        }
        let point = this.$point()
        if(!(mount[point] instanceof Array)){
            return -1 // 通过容器暴露标志NOSEQ=-1
        }

        for(let [index, elem] of Object.entries(mount[point])){
            if(elem.$guid && (elem.$guid() === this.$guid())){
                return parseInt(index)
            }
        }
    })
}